#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QTextBrowser>
#include <QTextEdit>
#include "projectmanager.h"
#include <QWebView>
#include <QPlainTextEdit>
#include <Qsci/qsciscintilla.h>
#include <QVBoxLayout>
#include <QToolBar>
#include "searchpanel.h"
#include "codeeditor.h"
#include "navigationmanager.h"
#include "greppanel.h"
#include "grepmanager.h"
#include "gotocontrol.h"



class QComboBox;

namespace Ui {
class MainWindow;
}


class MainWindow : public QMainWindow
{
    Q_OBJECT
    
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    bool ensureProjectIsSaved();
    void updateToolbar();
    void addFile();
    void openProject();
    void importDirectory();
    void newProject();
    void updateWindowTitle();
    QString getTabType(int aIndex);
    void updateProjectView();
    void closeFileTab(QString aFile);
    void openProject(QString aProject);
    void checkFile(QString aFile);
    void showGrepPanel(bool aShow);
    void openGrepTab();
    void updateDumpView(QString aContent);
    void keyPressEvent(QKeyEvent *e);
    void reopenTabs();
    void showGoToControl();
    void hideGoToControl();
    bool isCodeTabSelected();
    void openSettingsTab();
    void updateSettingsView();
    void setupStyleSheet();
private slots:
    void open();
    void save();
    void quit();
    void onTabChanged(int aTab);
    void onLinkClicked(const QUrl & url);
    void onTextChanged();
    void onCompletionSelected(int aListId, const QString aItemText);
    void onToolbarAction(QAction * action);
    void onTabClose(int aIndex);
    void onEditorLinkClicked(QString aLink);
    void onCodeEditorScrolled(int aOffset);
    void onProjectFilterChanged(QString aText);
    void onSearchRequested();
    void onSearchPanelHide();
    void onFunctionChosen(QString aItem);
    void onGrepDonePressed();
    void onGrepPressed(QString aPattern);
    void onGoToChosen(QString aLink);
    void onWebViewScrolled(int dx, int dy, const QRect & rectToScroll);
    void onAddTabPressed();
private:
    //Ui::MainWindow *ui;
    QAction *openAction;
    QAction *saveAction;
    QAction *exitAction;

    QMenu *m_fileMenu;
    QTabBar *m_tabBar;
    QWebView *m_projectView;
    CodeEditor * m_codeEditor;
    ProjectManager * m_projectManager;
    bool m_processTabChanges;
    bool m_processFunctionsListChanges;
    QToolBar * m_toolbar;
    GoToControl * m_gotoControl;
    //images
    QIcon m_saveImage;
    QIcon m_saveAllImage;
    QIcon m_quitImage;
    QIcon m_openProjectImage;
    QIcon m_addFilesImage;
    QIcon m_importDirectoryImage;
    QIcon m_newProjectImage;
    QIcon m_findImage;
    QIcon m_forwardImage;
    QIcon m_backImage;
    QIcon m_checkImage;
    QIcon m_grepImage;
    QIcon m_settingsImage;
    QIcon m_addTabImage;
    SearchPanel * m_searchPanel;
    QLineEdit * m_projectFilter;
    QComboBox * m_functionsList;
    NavigationManager * m_navigationManager;
    GrepPanel * m_grepPanel;
    QTextBrowser * m_dumpView;
    GrepManager * m_grepManager;
    int m_projectScrollPosition;
    int m_settingsScrollPosition;
private:
    void openProjectTab();
    void openCodeTab(LuaFile * aFile);
    void setupCodeEditor(QVBoxLayout *aLayout);
    void setupToolbar(QVBoxLayout *aLayout);
    void setupTabbar(QVBoxLayout *aLayout);
    void closeEvent(QCloseEvent *e);
    //void onFindTextChanged(QString aNewText);
    QString getCurrentTabType();
};

#endif // MAINWINDOW_H
